import math
import numpy as np
def hsv_to_rgb(h, s, v):
    if h == 1.0:
        h_6 = 0.0
    else:
        h_6 = 6 * h

    h_i = int(math.floor(h_6))
    f = h_6 - h_i

    p = v * (1.0 - s)
    q = v * (1.0 - f * s)
    t = v * (1.0 - (1.0 - f) * s)

    if h_i == 0:
        return (v, t, p)
    elif h_i == 1:
        return (q, v, p)
    elif h_i == 2:
        return (p, v, t)
    elif h_i == 3:
        return (p, q, v)
    elif h_i == 4:
        return (t, p, v)
    elif h_i == 5:
        return (v, p, q)
    else:
        return (0.0, 0.0, 0.0)

def get_color(id):
    """
    输出 (r,g,b) 颜色信息(0~255)
    """
    # 定义常量
    kInitialHue = 0.69
    kSaturation = 0.85
    kValue = 0.77
    kGoldenRatioConjugate = 0.6180339887498949
    hue = (kInitialHue + kGoldenRatioConjugate * id) % 1.0
    return float_color_to_uint8_color(hsv_to_rgb(hue, kSaturation, kValue))

def float_color_to_uint8_color(color):
    return (
        np.uint8(color[0] * 255),
        np.uint8(color[1] * 255),
        np.uint8(color[2] * 255)
    )